package fr.mobile2you.golfplus.gui;

import net.rim.device.api.i18n.ResourceBundle;
import net.rim.device.api.ui.Color;
import net.rim.device.api.ui.Font;
import net.rim.device.api.ui.Screen;
import net.rim.device.api.ui.TransitionContext;
import net.rim.device.api.ui.Ui;
import net.rim.device.api.ui.UiApplication;
import net.rim.device.api.ui.UiEngineInstance;
import net.rim.device.api.ui.component.StandardTitleBar;
import net.rim.device.api.ui.container.HorizontalFieldManager;
import net.rim.device.api.ui.container.MainScreen;
import fr.mobile2you.golfplus.gui.common.CustomLabelField;

public class DefaultScreen extends MainScreen implements labelsResource {
	protected ResourceBundle resources = ResourceBundle.getBundle(BUNDLE_ID,
			BUNDLE_NAME);
	private HorizontalFieldManager header;
	private static String _pin;

	public DefaultScreen() {
		super(NO_SYSTEM_MENU_ITEMS);
		header = new HorizontalFieldManager();

		add(header);
		StandardTitleBar titleBar = new StandardTitleBar();
		//titleBar.addClock();
		//titleBar.addSignalIndicator();
		titleBar.addTitle(resources.getString(TITLE));
		setTitleBar(titleBar);
		//add(new SeparatorField());
		//createHeader();
	}

	protected void createHeader() {
		header.deleteAll();
		header.setPadding(5, 5, 5, 5);
		// Bitmap icon = Bitmap.getBitmapResource("logo.png");
		// BitmapField logo = new BitmapField(icon);
		// logo.setPadding(new XYEdges(5, 10, 5, 5));
		// header.add(logo);
		header.add(new CustomLabelField(resources.getString(TITLE),
				FIELD_VCENTER, Color.BLUE, Font.getDefault().derive(Font.BOLD,
						20)));

//		header.add(new CustomLabelField(" - " + getPin(), FIELD_VCENTER,
//				Colors.BLUE, Font.getDefault().derive(Font.BOLD, 20)));

	}

	protected void rePaint() {
		createHeader();
	}

	public boolean onSavePrompt() {
		return true;
	}

	public boolean onClose() {
		return super.onClose();
	}

	public void startTransition(Screen newScreen) {

		TransitionContext transitionContextIn;
		TransitionContext transitionContextOut;
		UiEngineInstance engine = Ui.getUiEngineInstance();

		transitionContextIn = new TransitionContext(
				TransitionContext.TRANSITION_FADE);
		transitionContextIn.setIntAttribute(TransitionContext.ATTR_DURATION,
				500);
		transitionContextIn.setIntAttribute(TransitionContext.ATTR_DIRECTION,
				TransitionContext.DIRECTION_UP);

		transitionContextOut = new TransitionContext(
				TransitionContext.TRANSITION_FADE);
		transitionContextOut.setIntAttribute(TransitionContext.ATTR_DURATION,
				800);
		transitionContextOut.setIntAttribute(TransitionContext.ATTR_DIRECTION,
				TransitionContext.DIRECTION_UP);
		transitionContextOut.setIntAttribute(TransitionContext.ATTR_KIND,
				TransitionContext.KIND_OUT);

		engine.setTransition(null, newScreen, UiEngineInstance.TRIGGER_PUSH,
				transitionContextIn);
		engine.setTransition(newScreen, null, UiEngineInstance.TRIGGER_POP,
				transitionContextOut);

		synchronized (UiApplication.getEventLock()) {
			UiApplication.getUiApplication().pushScreen(newScreen);
		}
	}



}
